package com.mondo.financialwallet.presentation.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.TextView;

import com.example.common.ui.BaseActivity;
import com.mondo.financialwallet.R;
import com.mondo.financialwallet.presentation.model.TokenTransactionRecord;
import com.mondo.financialwallet.presentation.utils.ActivityTitleBarHelper;
import com.mondo.financialwallet.presentation.utils.AndroidUtils;
import com.mondo.financialwallet.presentation.utils.Toasts;

import butterknife.Bind;

/**
 * 货币账单详情
 */
public class TransactionRecordActivity extends BaseActivity {

    private static final String RECORD_TYPE = "RECORD";

    public static void launch(Context context, TokenTransactionRecord record) {
        context.startActivity(
                new Intent(context, TransactionRecordActivity.class)
                        .putExtra(RECORD_TYPE, record)
        );
    }

    @Bind(R.id.amount_text_view) TextView mAmountTextView;
    @Bind(R.id.status_text_view) TextView mStatusTextView;
    @Bind(R.id.send_address_text) TextView mSendAddressText;
    @Bind(R.id.receiving_address_text) TextView mReceivingAddressText;
    @Bind(R.id.remark_text) TextView mRemarkText;
    @Bind(R.id.transaction_number_text) TextView mTransactionNumberText;
    @Bind(R.id.block_height_text) TextView mBlockHeightText;
    @Bind(R.id.trans_time_text) TextView mTransTimeText;
    @Bind(R.id.gas_text) TextView mGasTextView;

    @Override
    protected int getLayoutID() {
        return R.layout.activity_transaction_record;
    }

    @Override
    protected void initActions() {
        ActivityTitleBarHelper.init(this, R.string.title_transaction_record);

        // 记录详情
        TokenTransactionRecord record = (TokenTransactionRecord) getIntent()
                .getSerializableExtra(RECORD_TYPE);

        // 显示
        mAmountTextView.setText(record.getAmount() + "\t\t" + record.getName());
        mStatusTextView.setText(record.getStatusText());
        mStatusTextView.setTextColor(getResources().getColor(record.getStatusColor()));
        mSendAddressText.setText(record.getFromAddress());
        mReceivingAddressText.setText(record.getToAddress());
        mRemarkText.setText(record.getRemark());
        mTransactionNumberText.setText(record.getTransactionNumber());
        mBlockHeightText.setText(String.valueOf(record.getBlockHeight()));
        mTransTimeText.setText(record.getTime());

        // 手续费
        mGasTextView.setText(String.valueOf(record.getGas()));

        // 复制交易号
        mTransactionNumberText.setOnClickListener(v -> {
            AndroidUtils.copyToChipBoard(this, record.getTransactionNumber());
            Toasts.success(R.string.message_copy_success);
        });

        // 复制发送地址
        mSendAddressText.setOnClickListener(v -> {
            AndroidUtils.copyToChipBoard(this, record.getFromAddress());
            Toasts.success(R.string.message_copy_success);
        });

        // 复制收到地址
        mReceivingAddressText.setOnClickListener(v -> {
            AndroidUtils.copyToChipBoard(this, record.getToAddress());
            Toasts.success(R.string.message_copy_success);
        });
    }
}
